package ext.acae2.dms.parse.wc9;

import org.dom4j.Document;
import org.dom4j.Node;

import ext.acae2.dms.bean.EPMReferenceLinkBean;
import ext.acae2.util.LoadingXmlUtil;

public class ParseEPMReferenceLink {

	public static EPMReferenceLinkBean execute(String path) throws Exception{
		EPMReferenceLinkBean epmReferenceLinkBean = new EPMReferenceLinkBean();
		Document doc = LoadingXmlUtil.executeForDom4j(path);
		
		Node referencedByNode = doc.selectSingleNode("/EPMReferenceLink/referencedBy/ObjectReference/ufid");
		String referencedBy = referencedByNode.getText();
		String parentId = referencedBy.substring(referencedBy.lastIndexOf(":") + 1, referencedBy.substring(0,referencedBy.lastIndexOf("|")).lastIndexOf("|"));
		epmReferenceLinkBean.setParentId(parentId);
		
		Node referencesNode = doc.selectSingleNode("/EPMReferenceLink/references/ObjectReference/ufid");
		String references = referencesNode.getText();
		String childId = references.substring(references.lastIndexOf(":") + 1, references.substring(0,references.lastIndexOf("|")).lastIndexOf("|"));
		epmReferenceLinkBean.setChildId(childId);
		
		return epmReferenceLinkBean;
	}
	
}
